var debug = true;
var nav = navigator.userAgent.toLowerCase();
isIE=((nav.indexOf("msie") != -1) && (nav.indexOf("opera") == -1) && (nav.indexOf("omniweb") == -1));

function $(obj) {
	if(document.getElementById(obj))
	return document.getElementById(obj);
	else {
		if(debug)alert('$ 无法找到到对象: '+obj);
		//window.location.reload(true);
		exit();
	}
}

function getFileName(path,add) {
	path = path + '';
	if(add == false)
	return (path.substr(src.lastIndexOf('/')+1,path.lastIndexOf('.')-path.lastIndexOf('/')-1));
	else return (path.substr(path.lastIndexOf('/')+1));
}
function getFilePath(fileSrc) {
	fileSrc = fileSrc + '';
	return (fileSrc.substr(0,(fileSrc.lastIndexOf('/')+1)));
}

addEvent = function(obj, evenName, func) {
	if(typeof(obj) != Object) obj = $(obj);
	if('on' == evenName.substr(0,2)) evenName = evenName.substr(2);
	if (obj.attachEvent) {
		obj.attachEvent('on' + evenName, func);
	} else {
		obj.addEventListener(evenName, func, true);
	}
};

removeEvent = function(obj, evenName, func) {
	if(typeof(obj) != Object) obj = $(obj);
	if('on' == evenName.substr(0,2)) evenName = evenName.substr(2);
	if (obj.attachEvent) {
		obj.detachEvent('on' + evenName, func);
	} else {
		obj.removeEventListener(evenName, func, true);
	}
};

//GBK To Unicode
function G2U(str) {
	if(!str) return '';
	var arr = new Array();
	for(var i = 0;i<str.length;i++) {arr[i] = "&#" + str.charCodeAt(i) + ";"}
	{return(arr.toString().replace(/,/g,""));}
}
function isDefined(obj) {if('undefined' == typeof(obj)) return false; else return true;}
function error(msg){alert ('Error: ('+msg+')');}
function check_re(arr) {
	if('error@$#$%$%$&*&(&$#' == arr[0]) {
		if(debug)alert('Error: msg send error: ('+arr[1]+')');
		if(arr['sql'] && debug)
		document.write ('Error: msg send error: ('+arr[1]+')');
		exit();
	}
}
function getMousePos(e){
	if('undefined' != typeof(Global)) {
		Global.mouseClient.x=(!isIE)?e.pageX : event.clientX+ieTrueBody().scrollLeft;
		Global.mouseClient.y=(!isIE)?e.pageY : event.clientY+ieTrueBody().scrollTop;
	}
}
function ieTrueBody(){
	return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}
/////////////////////////////////////////////////////

function Init() {
	doresize();
	window.onresize = doresize;
}

function doresize() {
	var height = getClientHeight() - (60+8+1+25+1+0+0+0+1+8+62+8) +70; /*jsdomenu*/
	var height2 = height - 13 - (document.getElementById('infodiv').style.display == 'none' ? 0 : 75)
	setElementStyle('height',height+'px','buddylist','networklogin','identity')
	setElementStyle('height',height2+'px','blist','olist')

	var width = parseInt(getClientWidth() * .96 - 2); /*jsdomenu*/
	setElementStyle('width',width+'px','buddylist','networklogin','identity')
	setElementStyle('width',width+'px','blist','olist','infodiv')
}

function setElementStyle(name, value) {
	for (var i = 2; i < arguments.length; i++)
	document.getElementById(arguments[i]).style[name] = value
}

/////////////////////////////////////////////////////


var lastShownList = "buddylisto"

function ShowPanel(panel) {
	if (panel == "signout") {
		redirect('../../more/SignOut.php', true);
		return;
	}

	setElementStyle('display','none','buddylist','networklogin','identity')

	var midcap = null;
	if (panel == "networklogin") {
		initNetworks();
		networkReset();
		midcap = "New Network Login"
	} else if (panel == "identity") {
		midcap = "Accounts Management"
	} else if (panel == "buddylist") {
		midcap = "Manage List"
		document.getElementById("olist").style.display = "none"
		document.getElementById("blist").style.display = "block"
		lastShownList = panel
	} else if (panel == "buddylisto") {
		midcap = "Online List"
		document.getElementById("blist").style.display = "none"
		document.getElementById("olist").style.display = "block"
		lastShownList = panel
		panel = "buddylist"
	}
	//if (selIndex != -1) document.f2.navselect.selectedIndex = selIndex;
	if (midcap) document.getElementById("midcaption").innerHTML = midcap;
	document.getElementById(panel).style.display = "block";
}


function toggleInfo() {
	showInfo(document.getElementById('infodiv').style.display == 'none')
}
function showInfo(bool) {
	document.getElementById('infodiv').style.display = bool ? 'block' : 'none';
	document.infoimg.src = bool ? 'img/info-close.gif' : 'img/info-open.gif'
	doresize();
}